<?php

class spDraggableClone extends spDiv
{
	private $row;
	private $sortableContainer;
	
	public function  __construct( $data=null )
	{
		parent::__construct( $data );

		$this->sortableContainer =  $this->createSortableContainer();
		
		$table = new spTable;
		$this->row = $table->addRow(array(
			$this->createDraggableContainer(),
			$this->sortableContainer
		));
		parent::addChild( $table );
		
		if ( isset($data["addCols"]) )
		{
			foreach ( $data["addCols"] as $c )
			{
				$this->addCol( $c );
			}
		}
	}
	
	public function addCol( $c )
	{
		$this->row->addCell( $c );
	}
	
	// add to sortable list
	public function add( $c )
	{
		$draggable = new spListItem(array(
			"class" => "spDraggable"
		));
		$draggable->addChild( $c );
	
		$this->sortableContainer->addChild( $draggable );
	}
	
	public function createDraggableContainer()
	{
		$draggableContainer = new spUnorderedList(array(
			"class" => "spDraggableMenu"
		));		
			
		foreach ( parent::getData("draggableContent") as $d )
		{
			$draggable = new spListItem(array(
				"class" => "spDraggable"
			));
			$draggable->addChild( $d );
			$draggableContainer->addChild( $draggable );
		}		
		
		return $draggableContainer;
	}
	
	public function createSortableContainer()
	{
		$ul = new spUnorderedList(array(
			"class"=>"spSortableContainer"
		));
		return $ul;
	}
}

?>